package com.silence.springboot.convert;

import com.silence.springboot.dto.BookBaseJoinAuthorDto;
import com.silence.springboot.dto.BookStatusAdminDto;
import com.silence.springboot.dto.BookStatusJoinAuthorDto;
import com.silence.springboot.entity.BookBaseEntity;
import com.silence.springboot.enums.BookStatusEnum;
import com.silence.springboot.vo.input.InsertBookInput;
import com.silence.springboot.vo.input.UpdateBookInput;
import com.silence.springboot.vo.output.PageBookBaseInfoOutput;
import com.silence.springboot.vo.output.PageBookStatusAdminOutput;
import com.silence.springboot.vo.output.PageBookStatusOutput;
import com.silence.springboot.vo.output.SelectAllOutput;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import java.util.List;

/**
 * @author silence
 * @email 792245022@qq.com
 * @create 2023-09-20 10:29
 */
@Mapper(componentModel = "spring")
public interface BookBaseConvert {

    /**
     * 新建入库入参转换
     *
     * @param input 新建入库入参
     * @return 登录实体
     */
    BookBaseEntity insertBookInputToBookBaseEntity(InsertBookInput input);

    /**
     * 更新信息入参转换
     *
     * @param input 更新信息入参
     * @return 登录实体
     */
    @Mapping(source = "bookId", target = "id")
    BookBaseEntity updateBookInputToBookBaseEntity(UpdateBookInput input);

    /**
     * 分页查询图书信息
     *
     * @param dto 入参
     * @return 分页结果
     */
    PageBookBaseInfoOutput toPageBookBaseInfoOutput(BookBaseJoinAuthorDto dto);

    /**
     * 查询信息
     *
     * @param entity 图书信息表实体类
     */
    @Mapping(source = "bookStatus", target = "bookStatus", qualifiedByName = "bookStatusEnumToString")
    @Mapping(source = "borrowTime", target = "borrowTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    @Mapping(source = "returnTime", target = "returnTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    @Mapping(source = "overdueTime", target = "overdueTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    SelectAllOutput toSelectAllOutput(BookBaseEntity entity);

    /**
     * 查询信息
     *
     * @param entityList 图书信息表实体类
     */
    List<SelectAllOutput> toSelectAllOutputList(List<BookBaseEntity> entityList);

    /**
     * 图书状态枚举转换为字符串
     *
     * @param status 图书状态枚举
     * @return 图书状态字符串
     */
    @Named(value = "bookStatusEnumToString")
    default String bookStatusEnumToString(String status) {
        return BookStatusEnum.getDescByCode(status);
    }


    /**
     * 分页查询图书状态信息
     *
     * @param dto 入参
     * @return 分页结果
     */
    @Mapping(source = "borrowTime", target = "borrowTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    @Mapping(source = "returnTime", target = "returnTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    PageBookStatusOutput toPageBookStatusOutput(BookStatusJoinAuthorDto dto);

    /**
     * 分页查询图书状态信息
     *
     * @param dto 入参
     * @return 分页结果
     */
    @Mapping(source = "borrowTime", target = "borrowTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    @Mapping(source = "returnTime", target = "returnTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    PageBookStatusAdminOutput toPageBookStatusAdminOutput(BookStatusAdminDto dto);

}
